

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taotao.settings.dev")
    import django
    django.setup()


    def banner_update():
        from home import ser
        from home import models
        from django.core.cache import cache
        from django.conf import settings
        queryset_banner = models.Banner.objects.filter(is_delete=False, is_show=True).order_by('orders')[
                          :settings.BANNER_COUNTER]
        ser_banner = ser.BannerSerializer(instance=queryset_banner, many=True)
        print(ser_banner.data)  # OrderedDict([('name', 'banner2'), ('link', 'actual-course'), ('img', '/media/banner/banner2.png')
        '''
        response(ser_banner.data)返回的img是有自动拼接ip地址的
        data=ser_banner.data获取到的img地址没有ip地址，所以需要我们手动拼接
        '''
        for banner in ser_banner.data:
            banner['img'] = settings.BASE_URL + banner['img']
            print(banner['img'])
        # cache.set('banner_list', ser_banner.data)
        return True
    banner_update()